<!DOCTYPE html>
<html lang="pt-br">
    <head>

        <!-- jQuery -->
        <script src="js/jquery-1.7.2.min.js"></script>
        <!-- jQuery UI -->
        <script src="js/jquery-ui-1.8.21.custom.min.js"></script>
        <!-- transition / effect library -->
        <script src="js/bootstrap-transition.js"></script>
        <!-- alert enhancer library -->
        <script src="js/bootstrap-alert.js"></script>
        <!-- modal / dialog library -->
        <script src="js/bootstrap-modal.js"></script>
        <!-- custom dropdown library -->
        <script src="js/bootstrap-dropdown.js"></script>
        <!-- scrolspy library -->
        <script src="js/bootstrap-scrollspy.js"></script>
        <!-- library for creating tabs -->
        <script src="js/bootstrap-tab.js"></script>
        <!-- library for advanced tooltip -->
        <script src="js/bootstrap-tooltip.js"></script>
        <!-- popover effect library -->
        <script src="js/bootstrap-popover.js"></script>
        <!-- button enhancer library -->
        <script src="js/bootstrap-button.js"></script>
        <!-- accordion library (optional, not used in demo) -->
        <script src="js/bootstrap-collapse.js"></script>
        <!-- carousel slideshow library (optional, not used in demo) -->
        <script src="js/bootstrap-carousel.js"></script>
        <!-- autocomplete library -->
        <script src="js/bootstrap-typeahead.js"></script>
        <!-- tour library -->
        <script src="js/bootstrap-tour.js"></script>
        <!-- library for cookie management -->
        <script src="js/jquery.cookie.js"></script>
        <!-- calander plugin -->
        <script src='js/fullcalendar.js'></script>
        <!-- data table plugin -->
        <script src='js/jquery.dataTables.min.js'></script>

        <!-- chart libraries start -->
        <script src="js/excanvas.js"></script>
        <script src="js/jquery.flot.min.js"></script>
        <script src="js/jquery.flot.pie.min.js"></script>
        <script src="js/jquery.flot.stack.js"></script>
        <script src="js/jquery.flot.resize.min.js"></script>
        <!-- chart libraries end -->

        <!-- select or dropdown enhancer -->
        <script src="js/jquery.chosen.min.js"></script>
        <!-- checkbox, radio, and file input styler -->
        <script src="js/jquery.uniform.min.js"></script>
        <!-- plugin for gallery image view -->
        <script src="js/jquery.colorbox.min.js"></script>
        <!-- rich text editor library -->
        <script src="js/jquery.cleditor.min.js"></script>
        <!-- notification plugin -->
        <script src="js/jquery.noty.js"></script>
        <!-- file manager library -->
        <script src="js/jquery.elfinder.min.js"></script>
        <!-- star rating plugin -->
        <script src="js/jquery.raty.min.js"></script>
        <!-- for iOS style toggle switch -->
        <script src="js/jquery.iphone.toggle.js"></script>
        <!-- autogrowing textarea plugin -->
        <script src="js/jquery.autogrow-textarea.js"></script>
        <!-- multiple file upload plugin -->
        <script src="js/jquery.uploadify-3.1.min.js"></script>
        <!-- history.js for cross-browser state change on ajax -->
        <script src="js/jquery.history.js"></script>
        <!-- application script for Charisma demo -->
        <script src="js/charisma.js"></script>
        <script src="js/jquery.ui.datepicker-pt-BR.js"></script>
        <script src="js/jquery.validaCampos.js"></script>


        <!--
                        Charisma v1.0.0
        
                        Copyright 2012 Muhammad Usman
                        Licensed under the Apache License v2.0
                        http://www.apache.org/licenses/LICENSE-2.0
        
                        http://usman.it
                        http://twitter.com/halalit_usman
        -->
        <meta charset="iso-8859-1">
        <title>Sistema de gerenciamento de processos</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description"
              content="Charisma, a fully featured, responsive, HTML5, Bootstrap admin template.">
        <meta name="author" content="Muhammad Usman">

        <!-- The styles -->
        <link id="bs-css" href="css/bootstrap-cerulean.css" rel="stylesheet">
        <style type="text/css">
            body {
                padding-bottom: 40px;
            }

            .sidebar-nav {
                padding: 9px 0;
            }
        </style>
        <link href="css/bootstrap-responsive.css" rel="stylesheet">
        <link href="css/charisma-app.css" rel="stylesheet">
        <link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
        <link href='css/fullcalendar.css' rel='stylesheet'>
        <link href='css/fullcalendar.print.css' rel='stylesheet' media='print'>
        <link href='css/chosen.css' rel='stylesheet'>
        <link href='css/uniform.default.css' rel='stylesheet'>
        <link href='css/colorbox.css' rel='stylesheet'>
        <link href='css/jquery.cleditor.css' rel='stylesheet'>
        <link href='css/jquery.noty.css' rel='stylesheet'>
        <link href='css/noty_theme_default.css' rel='stylesheet'>
        <link href='css/elfinder.min.css' rel='stylesheet'>
        <link href='css/elfinder.theme.css' rel='stylesheet'>
        <link href='css/jquery.iphone.toggle.css' rel='stylesheet'>
        <link href='css/opa-icons.css' rel='stylesheet'>
        <link href='css/uploadify.css' rel='stylesheet'>

        <!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
                  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
                <![endif]-->

        <!-- The fav icon -->
        <link rel="shortcut icon" href="img/favicon.ico">

        <!-- function submit form -->
        <script type="text/javascript">
            var isValid = 1;

            $(function() {
                $.datepicker.setDefaults($.datepicker.regional["pt-BR"]);
            });

            function redirect() {
                hideModal();
                window.location.href = "index.html";
            }
            function hideModal() {
                $("#myModal").attr("style", "display: none");
                $('div.modal-backdrop').remove();
            }
            function isEmpty(field) {
                if (isValid == 0)
                    return;
                if (field.value.length == 0) {
                    alert("O campo nao pode ser vazio");
                    field.focus();
                    isValid = 0;
                }

            }

            function changeByOption() {
                var optionSelect = $("#tipoUsuario option:selected").val();
                handlerFields(optionSelect);
            }
            function changedTipoUsuario(changedEvent) {
                handlerFields(changedEvent.value);
            }
            function handlerFields(value) {
                if (value == "gerente") {
                    $("#fieldCodEscritorio").hide();
                    $("#fieldCodGerente").hide();
                    $("#fieldOabUsuario").hide();
                } else if (value == "estagiario") {
                    $("#fieldCodEscritorio").show();
                    $("#fieldCodGerente").show();
                    $("#fieldOabUsuario").hide();
                } else if (value == "advogado") {
                    $("#fieldOabUsuario").show();
                    $("#fieldCodEscritorio").show();
                    $("#fieldCodGerente").show();
                } else if (value == "secretaria") {
                    $("#fieldCodEscritorio").show();
                    $("#fieldCodGerente").show();
                    $("#fieldOabUsuario").hide();
                }
            }
            function submitCadastroUsuario() {
                isValid = 1;

                var tipo = document.getElementById('tipoUsuario');
                if (tipo.value != "gerente") {
                    if (document.formCadastro.codEscritorio.value.length == 0) {
                        alert("Verifique o campo codigo do escrit&aacute;rio!");
                        document.cadastro.codEscritorio.focus();
                        return false;
                    }
                    if (document.formCadastro.codGerente.value.length == 0) {
                        alert("Verifique o campo codigo do gerente!");
                        document.cadastro.codGerente.focus();
                        return false;
                    }
                }
                if (tipo.value == "advogado") {
                    if (document.formCadastro.oabUsuario.value.length == 0) {
                        alert("Verifique o campo OAB!");
                        document.cadastro.oabUsuario.focus();
                        return false;
                    }
                }
                var codEscritorio = document.getElementById('codEscritorio');
                var codGerente = document.getElementById('codGerente');
                var login = document.getElementById('loginUsuario');
                var senha = document.getElementById('senhaUsuario');
                var estado = document.getElementById('estadoUsuario');
                var nome = document.getElementById('nomeUsuario');
                var endereco = document.getElementById('enderecoUsuario');
                var cidade = document.getElementById('cidadeUsuario');
                var cep = document.getElementById('cepUsuario');
                var telefone = document.getElementById('telefoneUsuario');
                var celular = document.getElementById('celularUsuario');
                var email = document.getElementById('emailUsuario');
                var dtNasc = document.getElementById('dtNascUsuario');
                var oab = document.getElementById('oabUsuario');
                var cpf = document.getElementById('cpfUsuario');
                var rg = document.getElementById('rgUsuario');
                isEmpty(login);
                isEmpty(senha);
                isEmpty(estado);
                isEmpty(nome);
                isEmpty(endereco);
                isEmpty(cidade);
                isEmpty(cep);
                isEmpty(email);
                isEmpty(cpf);
                if (!isValid)
                    return false;
                var urlCadastro = "../index.php?cadastroUsuario/salvar&login="
                    + login.value + "&senha=" + senha.value + "&tipo_usuario="
                    + tipo.value + "&cod_escritorio=" + codEscritorio.value
                    + "&cod_gerente=" + codGerente.value + "&estado="
                    + estado.value + "&nome=" + nome.value + "&endereco="
                    + endereco.value + "&cidade=" + cidade.value + "&cep="
                    + cep.value + "&telefone_fixo=" + telefone.value
                    + "&telefone_movel=" + celular.value + "&email=" + email.value
                    + "&data_nascimento=" + dtNasc.value + "&numero_oab="
                    + oab.value + "&cpf=" + cpf.value + "&rg=" + rg.value;
                $
                .ajax({
                    url : urlCadastro,
                    success : function(result) {
                        var key = parseInt(result.replace(']', '').replace('[',
                        ''));
                        switch (key) {
                            case 0:
                                window
                                .alert("Erro ao cadastrar usu&aacute;rio. Entre em contato com o administrador do sistema.");
                                break;
                            case 1:
                                hideModal();
                                window
                                .alert("Usu&aacute;rio cadastrado com sucesso. Aguarde a confirma&aacute;&aacute;o do cadastro para acessar o sistema.");
                                window.location.href = "index.html";
                                break;
                            case 2:
                                window
                                .alert("Erro ao cadastrar usu&aacute;rio. O Login digitado n&aacute;o esta disponivel.");
                                break;
                            case 3:
                                window
                                .alert("Erro ao cadastrar usu&aacute;rio. Os codigos de gerente e escritorio s&aacute;o v&aacute;lidos.");
                                break;
                            default:
                                window
                                .alert("Erro ao cadastrar usu&aacute;rio. Entre em contato com o administrador do sistema.");
                                break;
                        }
                    },
                    error : function(request, status, errorThrown) {
                        alert("Erro ao cadastrar usu&aacute;rio. Entre em contato com o administrador do sistema.");
                    }
                });
            }
        </script>
    </head>

    <body>
        <div class="container-fluid">
            <div class="row-fluid">

                <div class="row-fluid">
                    <div class="span12 center login-header">
                        <h2>Bem vindo</h2>
                    </div>
                    <!--/span-->
                </div>
                <!--/row-->

                <div class="row-fluid">

                    <div class="well span5 center login-box">
                        <div style="display: none" class="alert alert-error"
                             id="divAlertErroAutenticacao">
                            <button type="button" class="close" data-dismiss="alert">x</button>
                            <strong>Erro!</strong> Usu&aacute;rio e/ou senha incorreto.
                        </div>
                        <div class="alert alert-info">Insira seu Login e Senha nos
                            campos abaixo</div>
                        <form class="form-horizontal" method="post">

                            <fieldset>
                                <div class="input-prepend" title="Usu&aacute;rio" data-rel="tooltip">
                                    <span class="add-on"><i class="icon-user"></i></span><input
                                        autofocus class="input-large span10" name="username"
                                        id="username" type="text" />
                                </div>
                                <div class="clearfix"></div>

                                <div class="input-prepend" title="Senha" data-rel="tooltip">
                                    <span class="add-on"><i class="icon-lock"></i></span><input
                                        class="input-large span10" name="password" id="password"
                                        type="password" />
                                </div>
                                <div class="clearfix"></div>

                                <p class="box-content  buttons" style="min-height: 100px;">
                                    <button type="button" class="btn btn-primary"
                                            onclick="validarAcesso()" style="width: 20%">Acessar</button>
                                    <button type="button" class="btn btn-info btn-setting"
                                            style="width: 50%">N&atilde;o tem cadastro? Clique
                                        aqui</button>
                                </p>

                            </fieldset>
                        </form>
                    </div>
                    <!--/span-->
                </div>
                <!--/row-->
            </div>
            <!--/fluid-row-->

        </div>
        <!--/.fluid-container-->
        <div class="modal hide fade" id="myModal" onload="changeByOption();">
            <div class="modal-body" style="min-height: 0px">
                <div class="row-fluid sortable">
                    <div class="box-content">
                        <form class="form-horizontal" name="formCadastro">
                            <fieldset>
                                <div class="control-group">
                                    <label class="control-label" for="loginUsuario">Login</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="loginUsuario"
                                               maxlength="50" type="text">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="senhaUsuario">Senha</label>
                                    <div class="controls">
                                        <input type="password" class="input-xlarge focused"
                                               id="senhaUsuario" maxlength="50" type="text">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="tipoUsuario">Tipo de
                                        usu&aacute;rio</label>
                                    <div class="controls">
                                        <select id="tipoUsuario" data-rel="chosen"
                                                onchange="changedTipoUsuario(this)">
                                            <option value="gerente">Gerente</option>
                                            <option value="advogado">Advogado (a)</option>
                                            <option value="secretaria">Secret&aacute;ria (o)</option>
                                            <option value="estagiario">Estagi&aacute;rio (a)</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="estadoUsuario">Estado</label>
                                    <div class="controls">
                                        <select id="estadoUsuario" data-rel="chosen">
                                            <option>AC</option>
                                            <option>AL</option>
                                            <option>AM</option>
                                            <option>AP</option>
                                            <option>BA</option>
                                            <option>CE</option>
                                            <option>DF</option>
                                            <option>ES</option>
                                            <option>GO</option>
                                            <option>MA</option>
                                            <option>MG</option>
                                            <option>MS</option>
                                            <option>MT</option>
                                            <option>PA</option>
                                            <option>PB</option>
                                            <option>PE</option>
                                            <option>PI</option>
                                            <option>PR</option>
                                            <option>RJ</option>
                                            <option>RN</option>
                                            <option>RO</option>
                                            <option>RR</option>
                                            <option>RS</option>
                                            <option>SC</option>
                                            <option>SE</option>
                                            <option>SP</option>
                                            <option>TO</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="nomeUsuario">Nome
                                        completo</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="nomeUsuario"
                                               maxlength="50" type="text"
                                               onBlur="trim(formCadastro.nomeUsuario)">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="enderecoUsuario">Endere&ccedil;o</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="enderecoUsuario"
                                               onBlur="trim(formCadastro.enderecoUsuario)" maxlength="80"
                                               type="text">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="cidadeUsuario">Cidade</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="cidadeUsuario"
                                               onBlur="trim(formCadastro.cidadeUsuario)" maxlength="35"
                                               type="text">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="cepUsuario">CEP</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="cepUsuario"
                                               onkeypress="validaCampos(this,cep)" maxlength="9" type="text">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="telefoneUsuario">Telefone
                                        (fixo)</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="telefoneUsuario"
                                               onkeypress="validaCampos(this,telefone)" maxlength="14"
                                               type="text">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="telefoneMovelUsuario">Telefone
                                        (m&oacute;vel)</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="celularUsuario"
                                               onkeypress="validaCampos(this,telefone)" maxlength="15"
                                               type="text">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="emailUsuario">E-mail</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="emailUsuario"
                                               onBlur="trim(formCadastro.emailUsuario); validaEmail(formCadastro.emailUsuario)"
                                               maxlength="50" type="text">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="dtNascUsuario">Data de
                                        nascimento</label>
                                    <div class="controls">
                                        <input type="text" class="input-xlarge datepicker"
                                               id="dtNascUsuario">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="cpfUsuario">CPF</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="cpfUsuario"
                                               onkeypress="validaCampos(this,cpf)"
                                               onBlur="validarCPF(formCadastro.cpfUsuario)" maxlength="14"
                                               type="text">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="rgUsuario">RG</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="rgUsuario" type="text"
                                               maxlength="12">
                                    </div>
                                </div>
                                <div class="control-group" id="fieldOabUsuario"
                                     style="display: none">
                                    <label class="control-label" for="oabUsuario">OAB</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="oabUsuario" type="text"
                                               maxlength="6">
                                    </div>
                                </div>
                                <div class="control-group" id="fieldCodEscritorio"
                                     style="display: none">
                                    <label class="control-label" for="codEscritorio">C&oacute;digo
                                        do escrit&oacute;rio</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="codEscritorio"
                                               maxlength="50" type="text">
                                    </div>
                                </div>
                                <div class="control-group" id="fieldCodGerente"
                                     style="display: none">
                                    <label class="control-label" for="codGerente">C&oacute;digo
                                        do gerente</label>
                                    <div class="controls">
                                        <input class="input-xlarge focused" id="codGerente"
                                               maxlength="50" type="text">
                                    </div>
                                </div>
                            </fieldset>
                            <!-- JAVASCRIPT DE TESTES TEMPOR&aacute;RIO-->
                            <script>
                                function validarAcesso() {
                                    var user = document.getElementById('username').value;
                                    var senha = document.getElementById('password').value;
                                    var alertSenhaErrada = document
                                    .getElementById('divAlertErroAutenticacao');
                                    var url = '../index.php?login/logar&user='
                                        + user + '&password=' + senha;
                                    alertSenhaErrada.s

                                    $
                                    .ajax({
                                        type : "GET",
                                        url : url,
                                        dataType : "json",

                                        success : function(data) {
                                            if (data.status
                                                && data.liberado) {
                                                window.location.href = data.url;
                                            } else {
                                                alertSenhaErrada.style.display = "block";
                                                if (!data.status)
                                                    alertSenhaErrada.innerHTML = "Senha  ou login incorreto(s)!";
                                                else
                                                    alertSenhaErrada.innerHTML = "Seu cadastro ainda nao foi aprovado , aguarde!";
                                            }
                                        },
                                        error : function(request, status,
                                        errorThrown) {
                                            alertSenhaErrada.style.display = "block";
                                        }
                                    });
                                }
                            </script>
                        </form>

                    </div>

                </div>
                <!--/row-->
            </div>
            <div class="modal-footer">
                <a href="#" class="btn" data-dismiss="modal" onclick="redirect()">Fechar</a>
                <a href="#" class="btn btn-primary"
                   onclick="return submitCadastroUsuario();">Cadastrar</a>
            </div>
        </div>
        <!-- external javascript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->




    </body>
</html>
